package leetcode.code1352;

import java.util.ArrayList;
import java.util.List;

public class ProductOfNumbers {

	int[] list;
	int mul;
	int zero;
	int index;

	public ProductOfNumbers() {
		list = new int[40000];
		mul = 1;
		zero = -1;
		index = 0;
	}

	public void add(int num) {
		if (num == 0) {
			zero = index;
			mul = 1;
		} else {
			mul *= num;
			list[index] = mul;
		}
		index++;

	}

	public int getProduct(int k) {
		int L = index - 1 - k;
		if (zero > L) {
			return 0;
		}
		if (zero == L) {
			return list[index - 1];
		}
		return list[index - 1] / list[L];
	}

}
